import Xml


ListUsr={
             'BackupInterval':'0',
             'SysTray':'1',
             'MCleanup':'2',
             'WCleanup':'3',
             'DCleanup':'4',
             'DiskCleanupAuto':'5',
             'DiskCleanupTreshold':'6'
             }

def creationUserPref():
    """ """
    
    List=[]
    List.append("BackupInterval_3600")
    List.append("SysTray_ON")
    List.append("MCleanup_OFF")
    List.append("WCleanup_OFF")
    List.append("DCleanup_OFF")
    List.append("DiskCleanupAuto_OFF")
    List.append("DiskCleanupTreshold_1024")
    Xml.createXmlUP('C:\\Program Files\\EasyBackupTool\\usrPreferences.xml', 'prefUSR', List)
    
def getValue(name):
    value = Xml.retrieveInfoXml('C:\\Program Files\\EasyBackupTool\\usrPreferences.xml', name)
    return value[0]

def setValue(name, Value):
    ListVal = Xml.retrieveAllXml('C:\\Program Files\\EasyBackupTool\\usrPreferences.xml')
    #for elem in ListVal:
    ListVal=[]
    for items in ListUsr.iterkeys():
        #print items
        value = items+'_'+getValue(items)
        ListVal.append(value)
    print ListVal
    index=99
    for elem in ListVal:
        split= elem.split('_')
        if split[0]==name:
           index=ListVal.index(elem) 
           break
    ListVal.pop(index)
    ListVal.insert(index,name+'_'+Value)
    Xml.createXmlUP('C:\\Program Files\\EasyBackupTool\\usrPreferences.xml', 'prefUSR', ListVal)
   
if __name__ == "__main__":
    creationUserPref()
    print getValue("SysTray")
    setValue('SysTray','OFF')
    setValue('SysTray','ON')
    